<?php

/**
 * If you are not authorized to modify this file, do NOT touch it.
 * @file Log.class.php
 * @author cble
 * @date 2010-12-4
 * @description This file contains the definition for log operation.
 */

if (!defined('IN_IMBA')) exit('Access Denied.');

/**
 * The following definitions are for log types.
 */
define('L_TYPE_RUNTIME', 0);
define('L_TYPE_EXCEPTION', 1);
define('L_TYPE_UNKNOWN', 2);

/**
 * The following definitions are for the log class.
 */
class ImbaLog
{
	//Different log will be written into different files.
	private static $type;
	//The log information that will be written into log files.
	private static $info;
	
	/**
     * @name SetLog
     * @author cble
     * @date 2010-12-6
     * @description
     *   Set the information of the log.
     * @parameters
     *   string $info: The information given by user.
     *   integer $type: The type of the information.
     * @return void
     */
	public static function SetLog($info, $type=L_TYPE_RUNTIME)
	{
		if (!($type>=0 && $type<=L_TYPE_UNKNOWN))
        {
        	$type = L_TYPE_UNKNOWN;
        }
		self::$info = date('Y/m/d H:i:s') . ' ----- ' . $info . "\r\n";
		self::$type = $type;
	}
	
	/**
     * @name SetLog
     * @author cble
     * @date 2010-12-5
     * @description
     *   Write the log into log file.
     * @parameters void
     * @return void
     */
	public static function WriteLog()
	{
		$typeDir = array('Runtime', 'Exception', 'Unknown');
		$dir = '././log/' . $typeDir[self::$type] . '.log';
		file_put_contents($dir, self::$info, FILE_APPEND | LOCK_EX);
	}
}

?>